import reader
from reader import *
import sexprs
from sexprs import *


print('pHex testing1')
str1,remaining = pHex.match('0x43a2FF4')
print(str1 == 70922228)
str1,remaining = pHex.match('0xF3A2FF454')
print(str1 == 65400730708)

print('pNat testing1')
str1,remaining = pNat.match('654654')
print(str1 == 654654)

print('pUnsigned testing1')
str1,remaining = pUnsigned.match('0x43a2FF4')
print(str1 == 70922228)
str1,remaining = pUnsigned.match('0H432')
print(str1 == 1074)
str1,remaining = pUnsigned.match('654654')
print(str1 == 654654)

print('pSigned testing1')
str1,remaining = pSigned.match('-1')
print(str1 == -1)
str1,remaining = pSigned.match('-0x43a2FF4')
print(str1 == -70922228)
str1,remaining = pSigned.match('+0x43a2FF4')
print(str1 == 70922228)
str1,remaining = pSigned.match('-0H432')
print(str1 == -1074)
str1,remaining = pSigned.match('-654654')
print(str1 == -654654)

print('pInt testing1')
str1,remaining = pInt.match('01234')
print(str1.val == 1234)
str1,remaining = pInt.match('+1234')
print(str1.val == 1234)
str1,remaining = pInt.match('0x43a2FF4')
print(str1.val == 70922228)
str1,remaining = pInt.match('-0H432')
print(str1.val == -1074)
str1,remaining = pInt.match('-654654')
print(str1.val == -654654)


print('pZero testing1')
str1,remaining = pZero.match('0')
print(str1 == 0)
str1,remaining = pZero.match('0x0')
print(str1 == 0)

print('pFraction testing1')
str1,remaining = pFraction.match('120/2')
print(str1.val == 60)
str1,remaining = pFraction.match('-0H432/4')
print(str1.val == -268.5)
try:
    str1,remaining = pFraction.match('120/0')
except pc.NoMatch:
    print(True)


print('pSymbol testing1')
str1,remaining = pSymbol.match('Ab 545cs')
print(str1.val == 'AB' and remaining == ' 545cs')
str1,remaining = pSymbol.match('$^*_=+')
print(str1.val == '$^*_=+')
str1,remaining = pSymbol.match('Osher123')
print(str1.val == 'OSHER123')
str1,remaining = pSymbol.match('let*')
print(str1.val == 'LET*')


print('pNewline testing1')
str1,remaining = pNewline.match('\\n')
print(ord(str1) == 10)

print('pReturn testing1')
str1,remaining = pReturn.match('\\r')
print(ord(str1) == 13)

print('pTab testing1')
str1,remaining = pTab.match('\\t')
print(ord(str1) == 9)

print('pFormfeed testing1')
str1,remaining = pFormfeed.match('\\f')
print(ord(str1) == 12)

print('pBackslash testing1')
str1,remaining = pBackslash.match('\\\\')
print(ord(str1) == 92)

print('pDoubleQuate testing1')
str1,remaining = pDoubleQuate.match('\\"')
print(ord(str1) == 34)

print('pLambda testing1')
str1,remaining = pLambda.match('\\l')
print(ord(str1) == 0x03bb)
print(str1 == chr(0x03bb))
print(chr(0x03bb))

print('pString testing1')
str1,remaining = pString.match(chr(34) + 'Yaniv levi loves \\l' + chr(34))
print(str1.val == 'Yaniv levi loves λ')
str1,remaining = pString.match(chr(34) + 'New line?\\nBla bla' + chr(34))
print(str1.val == '''New line?
Bla bla''')
str1,remaining = pString.match(chr(34) + 'Try to \\"' + chr(34))
print(str1.val == 'Try to "')
try:
    str1,remaining = pString.match(chr(34) + 'Try to \ ' + chr(34))
except pc.NoMatch:
    print(True)

print('pChar testing1')
str1,remaining = pChar.match('#\\newline')
print(ord(str1.val) == 10)
str1,remaining = pChar.match('#\\return')
print(ord(str1.val) == 13)
str1,remaining = pChar.match('#\\tab')
print(ord(str1.val) == 9)
str1,remaining = pChar.match('#\\page')
print(ord(str1.val) == 12)
str1,remaining = pChar.match('#\\lambda')
print(ord(str1.val) == 0x03bb)
str1,remaining = pChar.match('#\\x03bb')
print(ord(str1.val) == 0x03bb)
str1,remaining = pChar.match('#\\x05D0')
print(ord(str1.val) == 0x05D0)
str1,remaining = pChar.match('#\\א')
print(ord(str1.val) == 0x05D0)

print('pNil testing1')
str1,remaining = pNil.match('(       )')
print( isinstance(str1,Nil) )

print('pLineComment testing1')
str1,remaining = pLineComment.match(';(     asdasd  )\n')
print(str1 == '')

print('pSexpr testing: (+ 3 (* 4 5) 7)')
str1,remaining = pSexpr.match('(+ 3 (* 4 5) 7)')
print(str1)

print('pSexpr testing: (+ 3 (* 4 5) 7)')
str1,remaining = pSexpr.match('#;(+ 3 (* 4 5) 7) a')
print(str1)
print(remaining)

print('pQuote testing1')
str1,remaining = pQuote.match('′(+ 3 (* 4 5) 7)')
print(str1)

print('pQuote testing1')
str1,remaining = pQuote.match(',(+ 3 (* 4 5) 7)')
print(str1)

print('pVector testing1')
str1,remaining = pVector.match('#(+ 3 (* 4 5) 7/8)')
print(str1)



print('pSexpr testing: (if #f (/ 1 0))')
str1,remaining = pSexpr.match('(if #f (/ 1 0))')
print(str1)
print(remaining)

AbstractSexpr.readFromString('#;(+ 3 (* 4 5) 7) a')
str1,remaining =AbstractSexpr.readFromString("(lambda (x) (+ x 1))")
print(str1)
print(remaining)










